               ******  DATE OF THIS VERSION:  31 October 2008  ****** .
*****************   SEE REVISION HISTORY AT END OF FILE   ********************** .

* This syntax assumes a file named "iat.txt" having the following variables 
* as used in Web demo site IATs in mid-2008.

* VARIABLE NAME                    CONTENT  
* ----------------------      ------------------------------------------------------- .
* block_number                numeric:  0 to 6
* block_name                  string:   user-created
* block_trial_count           numeric:  no. of trials in the current block
* block_pairing_definition    string:   user-created
* study_name                  string:   user-created
* task_number                 numeric:  order of IAT in overall procedure
* task_name	                string:   user-created
* trial_number                numeric:  zero thru (block_trial_count - 1)
* trial_name                  string:   user-created
* trial_response              string:   user-created (a category name)
* trial_latency               numeric:  latency in ms
* trial_error                 numeric:  0=correct; 1=error
* session_id                  numeric:  subject identifier (a number of 7 or 8 digits) .

*This syntax works without detailed path names for files if 
*  (a) SPSS is started by double-clicking the filename of this syntax (.sps) file
*      in order to start SPSS, 
*          _AND_
*  (b) this syntax file is located in the same folder containing the data file .

************************************************************************ .
********************** STEP 1: READ IN THE DATA ************************ .
************************************************************************ .


GET DATA  /TYPE = TXT
 /FILE = 'implicit.txt'
 /DELCASE = LINE
 /DELIMITERS = "\t"
 /ARRANGEMENT = DELIMITED
 /FIRSTCASE = 2
 /IMPORTCASE = ALL
 /VARIABLES =
 BLOCK_NAME_S A6
 BLOCK_PAIRING_DEFINITION_S A18
 STUDY_NAME_S A30
 TASK_NAME_S A7
 TRIAL_NAME_S A29
 TRIAL_RESPONSE_S A10
 SESSION_ID F7.2
 SESSION_DATE A18
 TASK_NUMBER F1.0
 BLOCK_NUMBER F1.0
 BLOCK_TRIAL_COUNT F2.1
 TRIAL_NUMBER F2.1
 TRIAL_ERROR F1.0
 TRIAL_LATENCY F4.2
 ATTEMPT F1.0 .

* Check session_id and session_date range .
* AGGREGATE OUTFILE = * / BREAK = session_id / session_date = FIRST (session_date) .
* first session =  1057116	29OCT2008:20:16:52 .
* last  session =  1066618	04NOV2008:23:59:54 .

RENAME VARIABLES
 (session_id = subject)
 (block_number = block)
 (trial_number = trial)
 (trial_error = error)
 (trial_latency = RT)
 (trial_response_s = response)
 (block_pairing_definition_s = pairing_code) 
 (study_name_s = study_name) .

SELECT IF task_name_s ne "amprace" .
EXECUTE .

*********************************************************************************** .
* IF THERE ARE MULTIPE IATs IN THE FILE, IT IS BEST TO RUN THIS
* SYNTAX SEPARATELY TO CREATE AN OUTPUT FILE FOR EACH IAT .
* RENAME COMPUTED VARIABLES APPROPRIATELY AFTER EACH RUN .
* THEN COMBINE THEM USING 'MATCH FILES .... BY subject order' .
*********************************************************************************** .

VARIABLE LABELS  block "block number"
 / trial "trial number" .
VALUE LABELS  error 1 "error" 0 "correct" .

CROSSTABS block BY pairing_code .
CROSSTABS block BY block_trial_count .
CROSSTABS trial BY error .

*There are some stray trials in the data file - delete .
SELECT IF (block ne 11) .
EXECUTE .

*Start block and trial numbers from 1, rather than zero .
COMPUTE block = block + 1 .
COMPUTE trial = trial + 1 .
EXECUTE .

*Get an idea of order effects .
MEANS RT BY block .


*******  IN THE FOLLOWING "IF" and "VALUE LABLES" COMMANDS:  ******* .
** replace "string_1" with string found within the pairing_code for  .
**  the pairing that is associated with high scores on the D measure .
** replace "string_2" with string found within the pairing_code for  .
**   the pairing that is associated with low scores on the D measure .
** Below the asterisked lines are lines that work with the sample    .
** "iat.txt" file provided with this generic script                    .
******************************************************************** .

*IF (INDEX(pairing_code,'string_1')>0) PAIRING = 1.
*IF (INDEX(pairing_code,'string_2')>0) PAIRING = 2.

IF (INDEX(pairing_code,"White")>=1) pairing=1 .
IF (INDEX(pairing_code,"Black")>=1) pairing=2 .

EXECUTE .

VARIABLE LABELS  pairing "focal category" .
*VALUE LABELS pairing  1 'string_1 pairing' 2 'string_2 pairing' .
VALUE LABELS pairing  1 'White focal' 2 'Black focal' .
FREQUENCIES pairing .
 
*Code the order variable. 
IF (pairing=1 & mod(block,2)=1) order=1 .
IF (pairing=1 & mod(block,2)=0) order=2 .
IF (pairing=2 & mod(block,2)=1) order=2 .
IF (pairing=2 & mod(block,2)=0) order=1 .
EXECUTE .

VARIABLE LABELS order "order of combined tasks" .
*VALUE LABELS order  1 'string_1 pairing first'  2 'string_2 pairing first' .
VALUE LABELS order  1 'White focal first'  2 'Black focal first' .
FREQUENCIES order .

*Add a position variable to indicate whether the IAT was 1st, 2nd, or 3rd .
IF (block=1 | block=2 | block=3 | block=4 | block=5 | block=6) position=1 .
*IF (block=9 | block=10 | block=11 | block=12) position=2 . 
VARIABLE LABELS position "ordinal position of IAT" .
VALUE LABELS position 1 '1st IAT' 2 '2nd IAT' .
FREQUENCIES position .

*Identify test variable to indicate 1st or 2nd block of each pairing .
IF (block=1 | block=2 ) test=0 .
IF (block=3 | block=4 ) test=1 .
IF (block=5 | block=6) test=2 .
VARIABLE LABELS  test "combined task block" .
VALUE LABELS test 0 'practice' 1 '1st post-practice' 2 '2nd post-practice'.
FREQUENCIES test .

*Finally, add a variable to code which IAT it is.
IF (INDEX(pairing_code,"White")>0) OR (INDEX(pairing_code,"Black")>0) IAT_type=1 .
IF (INDEX(pairing_code,"Mccain")>0) OR (INDEX(pairing_code,"Obama")>0) IAT_type=2 .

*Note that IAT_type labels identify direction of scoring.  
*High scores = greater assn of McCain than Obama with the concept .
VARIABLE LABELS IAT_type "IAT type" .
VALUE LABELS IAT_type 1 'White good' 2 'McCain good' .
CROSSTABS block BY IAT_type .

DESCRIPTIVES ALL . 


****************************************************************** .
**** STEP 2: COMPUTE CRITERIA FOR POSSIBLE SUBJECT DELETION ****** .
****************************************************************** .
*** First drop practice blocks .
** For initial analysis, keeping practice blocks .
*SELECT IF (block ne 1 & block ne 2 & block ne 7 & block ne 8) .
EXECUTE .


* NOTE: TG added commands to the AGGREGATE steps to keep track of the three different IATs .
* Also added numbers to filenames to allow processing multiple files with MACRO .

*Mark trials with latency < 300 ms (for possible subject discard) .
COMPUTE flag_300 = 0 .
IF (RT < 300) flag_300 = 1 .
*Mark trials with latency < 400 ms (to provide a count of these) .
COMPUTE flag_400 = 0 .
IF (RT < 400) flag_400 = 1 .
*Mark trials with latency > 5000 ms (to provide a count of these) .
COMPUTE flag_5K = 0 .
IF (RT GT 5000) flag_5K = 1 .
*Mark trials with latency > 5000 ms (to provide a count of these) .
COMPUTE flag_2K = 0 .
IF (RT GT 2000) flag_2K = 1 .
*Mark trials with latency > 10000 ms (to provide a count of these) .
COMPUTE flag_10K = 0 .
IF (RT GT 10000) flag_10K = 1 .

*Following line checks frequencies of fast & slow responses & errors .
FREQUENCIES flag_300 flag_400 flag_2K flag_5K flag_10K error .

*Record criteria for potential use in subject discards .

*This count can later be used as the basis for subject discard .
AGGREGATE OUTFILE = 'criteria.sav'
 / BREAK = subject IAT_type order session_date
 / pct_300 = PGT(flag_300,0) 
 / pct_400 = PGT(flag_400,0)
 / pct_2K = PGT(flag_2K,0)
 / pct_5K = PGT(flag_5K,0)
 / pct_10K = PGT(flag_10K,0)
 / aveltncy = MEAN (RT)
 / error_pct = PGT(error,0)
 / ntrials = N .

****************************************************************** .
********************* STEP 3: COMPUTE D-biep ********************* .
****************************************************************** .
*The following recoding commands are appropriate for Brief IATs (acc to data analyzed by Dan Chen) .
*Recode trials slower than 2000 ms to 2000 for RT .
IF (RT > 2000) RT = 2000 .
* Recode trials faster than 400 ms to 400 for RT
IF (RT < 400) RT = 400 .
EXECUTE .

* The computation needs an "inclusive SD" (all trials in blocks 1&2, 3&4, or 5&6 . 
*  but this can be computed from the individual block means and SDs .

* The following aggregate command computes block means needed for the D measures.
AGGREGATE OUTFILE = *
 / BREAK = subject IAT_type block order position pairing test 
 / Mn_RT = MEAN(RT) / pct_error = PGT (error,0) / SD_RT = SD(RT) 
 / ntrials = N .

IF (pairing = 1) N1 = ntrials .
IF (pairing = 2) N2 = ntrials .
IF (pairing = 1) M1 = Mn_RT .
IF (pairing = 2) M2 = Mn_RT .
IF (pairing = 1) error1 = pct_error .
IF (pairing = 2) error2 = pct_error .
IF (pairing = 1) SD1 = SD_RT .
IF (pairing = 2) SD2 = SD_RT .
EXECUTE .

AGGREGATE OUTFILE = *
 / BREAK = subject IAT_type order position test 
 / M1 M2 error1 error2 N1 N2 SD1 SD2 =
  FIRST(M1 M2 error1 error2 N1 N2 SD1 SD2) .

IF(test=0) error1_x = error1 .
IF(test=0) error2_x = error2 .
IF(test=1) error1_a = error1 .
IF(test=1) error2_a = error2 .
IF(test=2) error1_b = error1 .
IF(test=2) error2_b = error2 .
EXECUTE .

* Identify means, Ns, and SDs needed for D_biep computation .

COMPUTE D_biep_num = M2 - M1 .

COMPUTE D_biep_denom = SQRT( ( ((N1-1) * SD1**2 + (N2-1) * SD2**2)
                   + ((N1+N2) * ((M1-M2)**2) / 4) ) / (N1 + N2 - 1) ) .
EXECUTE .

IF (TEST=0) D_BIEP_x = D_biep_num / D_biep_denom .
IF (TEST=1) D_BIEP_a = D_biep_num / D_biep_denom .
IF (TEST=2) D_BIEP_b = D_biep_num / D_biep_denom .
IF (TEST=0) Nx = N1+N2 .
IF (TEST=1) Na = N1+N2 .
IF (TEST=2) Nb = N1+N2 .

DESCRIPTIVES ALL .

AGGREGATE OUTFILE = *
 / BREAK = subject IAT_type order position
 / D_biep_x D_biep_a D_biep_b error1_x error2_x error1_a error2_a error1_b error2_b Nx Na Nb = FIRST
  (D_biep_x D_biep_a D_biep_b error1_x error2_x error1_a error2_a error1_b error2_b Nx Na Nb) .

*Compute unweighted combination of measures based on first and second blocks of combined tasks.
* !! Do this even if there are fewer trials in the first block because the first block has been found
*  to have as good or better validity, even with fewer trials (see Greenwald, Nosek, & Banaji, JPSP 2003) .
COMPUTE D_biep = (D_biep_a + D_biep_b) / 2 .
COMPUTE D_biep_all = (D_biep_x + D_biep_a + D_biep_b) / 3 .
COMPUTE errorx = MEAN(error1_x, error2_x) .
COMPUTE errora = MEAN(error1_a, error2_a) .
COMPUTE errorb = MEAN(error1_b, error2_b) .
EXECUTE .

VARIABLE LABELS
   Nx '# trials, practice'
 / Na '# trials, 1st combined blocks'
 / Nb '# trials, 2nd combined blocks'
 / D_biep_x 'D - built-in error penalty (practice)' 
 / D_biep_a 'D - built-in error penalty (1st comb. block)' 
 / D_biep_b 'D - built-in error penalty (2nd comb. block)' 
 / D_biep 'D - built-in error penalty (primary IAT measure)' 
 / D_biep_all 'D - built-in error penalty (incl. practice)' 
 / errorx 'error % for Blocks 1 & 2'
 / errora 'error % for Blocks 3 & 4'
 / errorb 'error % for Blocks 5 & 6' 
 / subject 'Session ID' .

*NOTE:  Error rates for practice+test measures are included in 'CONVLOG2&CONV_MS2.SAV' .
FORMATS  D_biep D_biep_all D_biep_x D_biep_a D_biep_b (F6.3) Nx Na Nb (F4.0) errorx errora errorb (F5.1) .

SORT CASES BY subject IAT_type order .
SAVE OUTFILE = 'D_biep.measures.sav' / DROP = error1_x error2_x error1_a error2_a error1_b error2_b .

DESCRIPTIVES  ALL .

********************************************************************* .
**** STEP 4: COMBINE D MEASURES WITH SELECTION CRITERIA AND SAVE **** .
********************************************************************* .

*If desired, following commands can be used to combine and save all of the files .
MATCH FILES FILE = 'D_biep.measures.sav' / FILE = 'criteria.sav' / BY subject IAT_type order .
EXECUTE .

FORMATS aveltncy (F7.1) pct_300 pct_400 pct_10K error_pct (F6.1) subject (F8.0) .

*Add labels to variables in criteria.sav .
VARIABLE LABELS
   pct_300 '% latencies below 300 ms'
 / pct_400 '% latencies below 400 ms'
 / pct_10K '% latencies above 10,000 ms'
 / aveltncy 'Overall average latency (ms)'
 / error_pct 'Overall % errors' 
 / ntrials 'Total # of combined-task trials' .

*Note: No subjects have yet been discarded.  However, each record contains .
* three variables that might be used for discard .
* pct_300 = overall % of responses with latencies below 300 ms .
* error_pct = overall error % .
* aveltncy = overall average latency .
* [Note that 'aveltncy' was computed _BEFORE_ discard of latencies above 10000 ms] .

DESCRIPTIVES ALL .

MEANS D_biep D_biep_all BY order .
FREQUENCIES ntrials .

*Limit analyses to respondents who showed good cooperation with instructions on all three IATs.
COMPUTE filter$ = (ntrials=96) & (pct_300<10) & (pct_2K<20) & (error_pct<35) & (aveltncy<1700) .
FREQUENCIES filter$ .
FILTER BY filter$ .
DESCRIPTIVES ALL .

MEANS D_biep D_biep_all BY order .

FILTER OFF .
SAVE OUTFILE = "IAT.1_line_per_subject.sav" .

************  REVISION HISTORY ************* .
* 18 July 08:  Initial version created .
* 5 October 08:  Adapted to a specific (Mccain/Obama) Brief IAT expt with 3 BIATs .
* 31 October 08:  Adapted to a specific Brief IAT expt with 2 BIATs (Mccain/Obama + Bl/Wh race) .

